package server;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import util.Constant;
import util.UI;

public class Server {
	private final int LENGTH_QUEUE = 30;
	private final int THREAD_POLL_SIZE = 10;
	
	private ServerSocket socketServer;
	private ExecutorService poll;
	
	public Server(int port) throws IOException{
		socketServer = new ServerSocket(port,LENGTH_QUEUE);
		poll = Executors.newFixedThreadPool(THREAD_POLL_SIZE); // POLL com quantidade fixa de threads
		//util.UI ui = new UI();
		//ui.start();
	}
	public void start() throws IOException{
		System.out.println("Servico Iniciado...\n");
		while(true)
			poll.execute(new TaskServer(socketServer.accept()));
	}
	
	public static void main(String[] args) {
		try {
			Server server_1 = new Server(Constant.SERVER_PORT);
			server_1.start();
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
}
